package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.mapper.entity.Attribute;
import com.example.demo.mapper.entity.StudentAttribute;
import com.example.demo.mapper.entity.StudentAttributeView;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface AttributeManageMapper extends BaseMapper<Attribute> {
    @Select("SELECT * FROM attribute")
    List<Attribute> getAttributeList();

    @Delete("<script>" +
            "DELETE FROM attribute" +
            " WHERE attribute_id IN" +
            " <foreach collection='list' index='index' open='(' separator=',' close=')' item='attributeList' >" +
            "   #{attributeList.attributeId}" +
            " </foreach>" +
            "</script>")
    void deleteAttributeList(List<Attribute> attributeList);

    @Delete("DELETE FROM `attribute` WHERE attribute_id = #{attributeId}")
    void deleteAttributeById(Attribute attribute);

    @Update("UPDATE `attribute` SET name = #{name},description = #{description} WHERE attribute_id = #{attributeId}")
    void updateAttributeList(Attribute newAttribute);

    @Select("SELECT * FROM student_attribute_view")
    List<StudentAttributeView> getAttributeLog();

    @Update("UPDATE `student_attribute` SET value = #{value},last_updated = #{lastUpdated} WHERE id = #{id}")
    void updateAttributeLog(StudentAttribute newAttribute);

}
